Hello and welcome to this lecture.
In this lecture we aren't going to be creating some logic for move in the puddle the moment the pad
all his static so does not respond to movement.
This is what the paddle looks like at the moment.
So the little rectangle in blue there.
So if you press your left and right mouse key you will notice there is no movement at all.
That's because we have not implemented the logic that will control that movement.
So this is what we'll do in this lecture.
All right I have caught my javascript file here.
So we go right down to where we defined the draw function.
So this is where we are going to implement the logic for moving the paddle.
So this is the core function so this is where we go to implement it.
So we've got some more that code in here.
So we are just going to implement it.
Just underneath here with inside the drill function to save time I have written the piece of code already.
So this is the first part of the code.
This statement here.
So this is the first part of the code.
This same that if the right is press them is the right cursor or the right key on the keyboard is pressed
the variable pad X will move the paddle 7 pixels.
Kate remember we defined all these variables later on the cause saw powder X..
This is what part of exis is the whiff is encumbers with minus the paddle with divided by two.
Right so that's what that is so saying here that if the right key or cursings Press moved the pad all
seven pixels.
That's why there is a loss however or else what if the left is pressed more.
The paddle minus seven in the opposite direction.
So that's what that means.
Okay so if the right is pressed move the paddle 7 pixels and if it's left move it 7 pixels the other
direction.
So let's say this and run this.
I run the code so you can see while you are right so this is the paddle at the moment.
So at the moment if I press the left.
If you notice is pedalos disappear off the screen and if I press the right it disappears off the screen
as well.
Okay so let's try and control the paddle.
Okay this is gone out of the.
So we have to try and correct that so that it stays within the compass all right.
I have implemented some extra things into the code to prevent the pad from leaving the canvas saw So
this is what it is say.
If the right cursor is pressed and this loop symbol's game is and and the pad all variable the variable
padlocked X is the less than the can that's a minus.
Me with the paddle and then move the pixels move the pad all 7 pixels.
Okay so if I were pressing the right cursor and this condition is true.
Move it to 7 pixels from the right.
In that case it will not leave the compass because of this extra implementation here.
Which I've said.
If there were when you press the right cursor and the pad or the variable paddleboat X is less than
the width of the canvas minus B with the paddle.
If the condition is true then move with 7 pixels.
Else it is not.
If you press the left cursor instead and the pad all x variable is greater than the zero from the left
as long as is greater than zero.
Then you can move the pad all 7 pixels away which is mine of 7.
The other in the other Derek.
So what this court is saying is if the curse of the left curser here is pressed the paddle will move
several pixels to the left.
If we press the right key right cursor it will move several pixels from the right.
The paddle may have seven pixels to the right.
And if you press the left to a more seven pixels to the left or right.
That's what Big code will do.
Okay.
We've also implemented extra things here to prevent the pad all from leave in the camp that's previously
without this extra things we've implemented here.
The paddle was leave in the comebacks.
Okay.
So what we're seeing now is that the the paddle x position is part of lexia is variable.
We use it to move from 0 on the left to from the left side of the come from zero minus the with of the
paddle.
Okay.
To the right size.
Right so with that in place the count the paddles should not leave the compass.
Okay.
Now that we've done that to save save your work and we know we've got all the functions in place now
so now if we try and go back to that you see that the paddle can be moved and it will not leave the
screen you can see that it does not leave the comebacks no matter how far you press it to the left or
how far you press it to the right.
It does not leave the compass because of the front perimenopause.
We have put in place to control that.
All right so sit for this shot on the logic to move the panel.
So we've got our game you know looking good.
We now have to implement a game all of us so there's no point playing a game that one can not lose at
some point in me you should lose the game.
The purpose of the game.
So we are going to create the mechanics for the game loss way is possible for someone to lose the game
in the next lecture.